package com.cooqe.snmp.utils;

import com.cooqe.basefinder.AbstractBaseFinder;
import org.apache.commons.lang3.StringUtils;
import org.snmp4j.PDU;
import org.springframework.stereotype.Component;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2023/11/14-2023
 * @Description: common util 工具类
 */
public class CommonUtil {

    //method
    public static int getSnmpMethodCode(String method) {
        int pduMethodCode = PDU.GET;
        if (StringUtils.isNotBlank(method)) {
            switch (method) {
                case "getNext":
                    pduMethodCode = PDU.GETNEXT;
                    break;
                case "set":
                    pduMethodCode = PDU.SET;
                default:
                    break;
            }
        }
        return pduMethodCode;
    }

    // 获取 simpleName
    public static String getContainerSimpleName(Class<? extends AbstractBaseFinder> clazz){
        String inContainerName = clazz.getAnnotation(Component.class).value();
        if (StringUtils.isBlank(inContainerName)) {
            String className = clazz.getSimpleName();
            String firstChar = className.substring(0, 1);
            inContainerName = firstChar.toLowerCase() + className.substring(1);
        }
        return inContainerName;
    }
}